<template>
  <div class="home">
    <!-- 英雄区域 -->
    <section class="hero">
      <div class="hero-content">
        <div class="hero-text">
          <h1 class="hero-title">
            {{ $t('home.greeting') }}
            <span class="highlight">{{ $t('global.siteName') }}</span>
          </h1>
          <p class="hero-subtitle">{{ $t('home.role') }}</p>
          <p class="hero-description">{{ $t('home.description') }}</p>
          <div class="hero-buttons">
            <el-button type="primary" size="large" @click="scrollToProjects">
              {{ $t('home.viewProjects') }}
            </el-button>
            <el-button size="large" @click="scrollToContact">
              {{ $t('home.contactMe') }}
            </el-button>
          </div>
        </div>
        <div class="hero-image">
          <img 
            src="https://q8.itc.cn/q_70/images03/20241030/7e4e379bf5b84b6c9fb4a9fec3102d5d.jpeg" 
            alt="Profile" 
            class="profile-image"
          />
        </div>
      </div>
    </section>

    <!-- 技能区域 -->
    <section class="skills" ref="skillsSection">
      <h2 class="section-title">{{ $t('home.skills') }}</h2>
      <div class="skills-grid">
        <div v-for="skill in skills" :key="skill.name" class="skill-card">
          <el-icon class="skill-icon">
            <component :is="skill.icon" />
          </el-icon>
          <h3>{{ skill.name }}</h3>
          <p>{{ skill.description }}</p>
          <div class="skill-level">
            <div class="skill-progress">
              <div 
                class="skill-progress-bar" 
                :style="{ width: `${skill.level}%` }"
              ></div>
            </div>
            <span>{{ skill.level }}%</span>
          </div>
        </div>
      </div>
    </section>

    <!-- 最新项目 -->
    <section class="recent-projects" ref="projectsSection">
      <h2 class="section-title">{{ $t('home.recentProjects') }}</h2>
      <div class="projects-grid">
        <el-card 
          v-for="project in recentProjects" 
          :key="project.id" 
          class="project-card"
          :body-style="{ padding: '0px' }"
        >
          <div class="project-image">
            <img :src="project.image" :alt="project.title" />
          </div>
          <div class="project-content">
            <h3>{{ project.title }}</h3>
            <p>{{ project.description }}</p>
            <div class="project-tags">
              <el-tag 
                v-for="tag in project.tags" 
                :key="tag"
                size="small"
                class="project-tag"
              >
                {{ tag }}
              </el-tag>
            </div>
            <div class="project-links">
              <el-button type="primary" link @click="viewProject(project)">
                {{ $t('home.learnMore') }}
              </el-button>
            </div>
          </div>
        </el-card>
      </div>
      <div class="view-all">
        <router-link to="/projects">
          <el-button type="primary">
            {{ $t('home.viewAllProjects') }}
          </el-button>
        </router-link>
      </div>
    </section>

    <!-- 联系区域 -->
    <section class="contact-section" ref="contactSection">
      <h2 class="section-title">{{ $t('home.getInTouch') }}</h2>
      <p class="contact-description">{{ $t('home.contactDescription') }}</p>
      <div class="contact-buttons">
        <router-link to="/contact">
          <el-button type="primary" size="large">
            {{ $t('home.sendMessage') }}
          </el-button>
        </router-link>
        <a href="mailto:xuyang11710@163.com">
          <el-button size="large">
            {{ $t('home.emailMe') }}
          </el-button>
        </a>
      </div>
    </section>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {
  Monitor,
  Iphone,
  Setting,
  TrendCharts,
  Link,
  Tools
} from '@element-plus/icons-vue'

const router = useRouter()

// 技能数据
const skills = [
  {
    name: 'Frontend Development',
    description: 'Vue.js, React, TypeScript, HTML5, CSS3',
    level: 90,
    icon: Monitor
  },
  {
    name: 'Mobile Development',
    description: 'React Native, Flutter, iOS, Android',
    level: 75,
    icon: Iphone
  },
  {
    name: 'Backend Development',
    description: 'Node.js, Python, Java, Databases',
    level: 85,
    icon: Setting
  },
  {
    name: 'Data Visualization',
    description: 'D3.js, Chart.js, SVG Animation',
    level: 80,
    icon: TrendCharts
  },
  {
    name: 'API Development',
    description: 'RESTful APIs, GraphQL, WebSockets',
    level: 85,
    icon: Link
  },
  {
    name: 'DevOps',
    description: 'Docker, CI/CD, Cloud Services',
    level: 70,
    icon: Tools
  }
]

// 最新项目数据
const recentProjects = [
  {
    id: 1,
    title: '个人作品集网站',
    description: '使用Vue 3和Element Plus构建的响应式个人网站',
    image: 'https://img2.baidu.com/it/u=3593088772,603041803&fm=253&fmt=auto&app=138&f=PNG?w=493&h=370',
    tags: ['Vue 3', 'TypeScript', 'Element Plus'],
    link: '/projects/portfolio'
  },
  {
    id: 2,
    title: '数据可视化仪表板',
    description: '实时数据分析和可视化展示平台',
    image: 'https://pic.rmb.bdstatic.com/bjh/240407/dump/df2ab855f4e2c81f4c0f0aec2e6ab10a.jpeg@h_1280',
    tags: ['D3.js', 'Node.js', 'WebSocket'],
    link: '/projects/dashboard'
  },
  {
    id: 3,
    title: '移动端电商应用',
    description: '基于React Native的跨平台电商应用',
    image: 'https://img0.baidu.com/it/u=2078330993,2295455596&fm=253&fmt=auto&app=120&f=JPEG?w=889&h=500',
    tags: ['React Native', 'Redux', 'Node.js'],
    link: '/projects/ecommerce'
  }
]

// 滚动到指定区域
const skillsSection = ref<HTMLElement | null>(null)
const projectsSection = ref<HTMLElement | null>(null)
const contactSection = ref<HTMLElement | null>(null)

const scrollToSection = (ref: HTMLElement | null) => {
  ref?.scrollIntoView({ behavior: 'smooth' })
}

const scrollToProjects = () => scrollToSection(projectsSection.value)
const scrollToContact = () => scrollToSection(contactSection.value)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const viewProject = (project: any) => {
  router.push(project.link);
}
</script>

<style scoped>
/* 保持现有样式不变 */
.home {
  min-height: 100vh;
}

.hero {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  padding: 60px 0;
  background: linear-gradient(135deg, var(--el-bg-color) 0%, var(--el-bg-color-page) 100%);
}

.hero-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 50px;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.hero-text {
  animation: fadeInUp 1s ease;
}

.hero-title {
  font-size: 3rem;
  margin-bottom: 1rem;
  line-height: 1.2;
}

.highlight {
  color: var(--el-color-primary);
}

.hero-subtitle {
  font-size: 1.5rem;
  color: var(--el-text-color-secondary);
  margin-bottom: 1.5rem;
}

.hero-description {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--el-text-color-regular);
  margin-bottom: 2rem;
}

.hero-buttons {
  display: flex;
  gap: 1rem;
}

.hero-image {
  display: flex;
  justify-content: center;
  align-items: center;
  animation: fadeInRight 1s ease;
}

.profile-image {
  width: 400px;
  height: 400px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.skills {
  padding: 80px 0;
  background-color: var(--el-bg-color-page);
}

.section-title {
  text-align: center;
  font-size: 2.5rem;
  margin-bottom: 3rem;
}

.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.skill-card {
  padding: 30px;
  background-color: var(--el-bg-color);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease;
}

.skill-card:hover {
  transform: translateY(-5px);
}

.skill-icon {
  font-size: 2.5rem;
  color: var(--el-color-primary);
  margin-bottom: 1rem;
}

.skill-card h3 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.skill-card p {
  color: var(--el-text-color-regular);
  margin-bottom: 1rem;
}

.skill-level {
  display: flex;
  align-items: center;
  gap: 10px;
}

.skill-progress {
  flex: 1;
  height: 6px;
  background-color: var(--el-border-color-lighter);
  border-radius: 3px;
  overflow: hidden;
}

.skill-progress-bar {
  height: 100%;
  background-color: var(--el-color-primary);
  border-radius: 3px;
  transition: width 1s ease;
}

.recent-projects {
  padding: 80px 0;
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
  max-width: 1200px;
  margin: 0 auto 40px;
  padding: 0 20px;
}

.project-card {
  height: 100%;
  transition: transform 0.3s ease;
}

.project-card:hover {
  transform: translateY(-5px);
}

.project-image {
  height: 200px;
  overflow: hidden;
}

.project-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.project-card:hover .project-image img {
  transform: scale(1.05);
}

.project-content {
  padding: 20px;
}

.project-content h3 {
  margin: 0 0 10px 0;
  font-size: 1.3rem;
}

.project-content p {
  color: var(--el-text-color-regular);
  margin-bottom: 15px;
}

.project-tags {
  margin-bottom: 15px;
}

.project-tag {
  margin-right: 5px;
  margin-bottom: 5px;
}

.view-all {
  text-align: center;
}

.contact-section {
  padding: 80px 0;
  background-color: var(--el-bg-color-page);
  text-align: center;
}

.contact-description {
  max-width: 600px;
  margin: 0 auto 2rem;
  color: var(--el-text-color-regular);
  font-size: 1.1rem;
  line-height: 1.6;
}

.contact-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (max-width: 768px) {
  .hero-content {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .hero-image {
    order: -1;
    margin-bottom: 30px;
  }

  .profile-image {
    width: 250px;
    height: 250px;
  }

  .hero-buttons {
    justify-content: center;
  }

  .contact-buttons {
    flex-direction: column;
    align-items: center;
  }
}
</style>
